package wrappers;

import entities.Employee;
import java.util.*;

/**
 *
 * @author Alejandro
 */
public class EmployeeWrap extends AbstractWrap {
    private Employee e;
    private ViewElement viewManager;
    private ViewElement viewDepartment;

    public EmployeeWrap(Employee _e) {
        e = _e;
    }

    public void setViewManager(ViewElement _manager) {
        viewManager = _manager;
    }

    public void setViewDepartment(ViewElement _department) {
        viewDepartment = _department;
    }

    public ViewElement getViewId() {
        return new ViewElement("id", Integer.toString(e.getId()));
    }

    public ViewElement getViewName() {
        return new ViewElement("name", e.getName());
    }

    public ViewElement getViewSurname() {
        return new ViewElement("surname", e.getSurname());
    }

    public ViewElement getViewJob() {
        return new ViewElement("job", e.getJob());
    }

    public ViewElement getViewDate() {
        return new ViewElement("date", e.getDate());
    }

    public ViewElement getViewSalary() {
        return new ViewElement("salary", Integer.toString(e.getSalary()));
    }

    public ViewElement getViewManager() {
        return viewManager;
    }

    public ViewElement getViewDepartment() {
        return viewDepartment;
    }

    @Override
    public int compareTo(Object o) {
        int result = 0;
        EmployeeWrap ew = (EmployeeWrap) o;
        switch(compareCase) {
            case 0: result = (isAscending) ? (this.e.getId() - ew.e.getId()) : (ew.e.getId() - this.e.getId());break;
            case 1: result = (isAscending) ? (this.e.getName().compareTo(ew.e.getName())) : (ew.e.getName().compareTo(this.e.getName()));break;
            case 2: result = (isAscending) ? (this.e.getSurname().compareTo(ew.e.getSurname())) : (ew.e.getSurname().compareTo(this.e.getSurname()));break;
            case 3: result = (isAscending) ? (this.e.getJob().compareTo(ew.e.getJob())) : (ew.e.getJob().compareTo(this.e.getJob()));break;
            case 4: result = (isAscending) ? (this.getViewManager().toString().compareTo(ew.getViewManager().toString())) : (ew.getViewManager().toString().compareTo(this.getViewManager().toString()));break;
            case 5: result = (isAscending) ? (this.e.getDate().compareTo(ew.e.getDate())) : (ew.e.getDate().compareTo(this.e.getDate()));break;
            case 6: result = (isAscending) ? (this.e.getSalary() - ew.e.getSalary()) : (ew.e.getSalary() - this.e.getSalary());break;
            case 7: result = (isAscending) ? (this.getViewDepartment().toString().compareTo(ew.getViewDepartment().toString())) : (ew.getViewDepartment().toString().compareTo(this.getViewDepartment().toString()));break;
        }
        return result;
    }

    @Override
    public List<String> getHeaders() {
        List<String> headers = new LinkedList<String>();
        headers.add(getViewId().getHeader());
        headers.add(getViewName().getHeader());
        headers.add(getViewSurname().getHeader());
        headers.add(getViewJob().getHeader());
        headers.add(getViewManager().getHeader());
        headers.add(getViewDate().getHeader());
        headers.add(getViewSalary().getHeader());
        headers.add(getViewDepartment().getHeader());
        return headers;
    }

    @Override
    public List<String> getCells() {
        List<String> cells = new LinkedList<String>();
        cells.add(getViewId().toString());
        cells.add(getViewName().toString());
        cells.add(getViewSurname().toString());
        cells.add(getViewJob().toString());
        cells.add(getViewManager().toString());
        cells.add(getViewDate().toString());
        cells.add(getViewSalary().toString());
        cells.add(getViewDepartment().toString());
        return cells;
    }

    @Override
    public String getPrimaryKey() {
        return getViewId().toString();
    }
}
